# 创建列表
list1 = []
list2 = [1, '2', True]
list3 = list()
list4 = list('345')
print(list1, list2, list3, list4)  # [] [1, '2', True] [] ['1', '2', '3']

# 列表加法
list5 = [1, 2, 3]
list6 = [4, 5, 6]
print(list5 + list6)  # [1, 2, 3, 4, 5, 6]

# 列表的乘法(列表重复)
list7 = ['hello ']
print(list7 * 3)  # ['hello ', 'hello ', 'hello ']

# 列表成员判断
list8 = [1, 10, False, '爱好']
print(1 in list8)  # True
print('True' not in list8)  # True

# 列表的遍历
list9 = ['smoke', 'drink', 'play', 'hit']
for i in list9:
    print(i, end='\t')  # smoke	drink	play	hit

for index, val in enumerate(list9):
    print(index, val, end='\t')  # 0 smoke	1 drink	2 play	3 hit

for i in range(len(list9)):
    print(i, list9[i], end='--')  # 0 smoke--1 drink--2 play--3 hit--，
print()

# 列表常用的方法 变量.方法名()
list10 = [1, 2, 3]
list10.insert(-1,4)
print(list10)  # [1, 2, 4, 3]
list10.append(5)
print(list10)  # [1, 2, 4, 3, 5]
list10.extend(['hello', 'world', '2025'])
print(list10)  # [1, 2, 4, 3, 5, 'hello', 'world', '2025']
del list10[-1]
print(list10)  # [1, 2, 4, 3, 5, 'hello', 'world']
list10.pop(1)
print(list10)  # [1, 4, 3, 5, 'hello', 'world']

# 二维列表
list11 = [1,2, [4, 5]]
print(list11)

# 求和年龄，求平均年龄
age = [10, 20, 30, 54, 67, 23, 90, 89, 72, 24]
print(sum(age))  # 479
print(sum(age) / len(age))  # 47.9
